<template>
	<view class="uni-tab-bar">
		<scroll-view id="tab-bar" class="uni-swiper-tab" scroll-x :scroll-left="scrollLeft" style="background: #fff;">
			<view v-for="(tab,index) in tabBars" :key="tab.id" :class="['swiper-tab-list',tabIndex==index ? 'active' : '']" :id="tab.id" :data-current="index" @tap="tapTab">{{tab.name}}</view>
		</scroll-view>
		
		<view style="display: flex;line-height: 80upx;">
			<view @click="changeisshow" :style="{color: ordercolor}" style="background-color: #fff;height: 80upx;line-height: 80upx;border-bottom: 1upx solid #ccc;flex: 1;text-align: center;">
					普通订单
			</view>
			<view @click="changeisshow1" :style="{color: ordercolor1}" style="background-color: #fff;height: 80upx;line-height: 80upx;border-bottom: 1upx solid #ccc;flex: 1;text-align: center;">
					拼团订单
			</view>
			<view @click="changeisshow2" :style="{color: ordercolor2}" style="background-color: #fff;height: 80upx;line-height: 80upx;border-bottom: 1upx solid #ccc;flex: 1;text-align: center;">
					抢购订单
			</view>
		</view>
		
		<swiper :current="tabIndex" class="swiper-box" duration="300" @change="changeTab" :style="{'height': systemInfo +'px'}">
			<swiper-item v-for="(tab,index1) in newsitems" :key="index1">
				<scroll-view class="list" scroll-y @scrolltolower="loadMore">
					
					<block v-if="isshow == true" v-for="(newsitem,index2) in tab.data" :key="index2">
						<media-list :data="newsitem"  @cancel="cancel(newsitem.order_number)" @confirm='confirm(newsitem.order_number)' @log="log(newsitem.order_number)" @evaluate="evaluate(newsitem.id)" @del="del(newsitem.id)" @pay="pay(newsitem.order_number,newsitem.pay_type)" @click="goDetail(newsitem.id)"></media-list>
					</block>
					
					<block v-if="isshow1 == true" v-for="(newsitem,index2) in tab.data_group" :key="index2">
						<media-list :data="newsitem"  @cancel="cancel(newsitem.order_number)" @confirm='confirm(newsitem.order_number)' @log="log(newsitem.order_number)" @evaluate="evaluate(newsitem.id)" @del="del(newsitem.id)" @pay="pay(newsitem.order_number,newsitem.pay_type)" @click="goDetail_group(newsitem.id)" @share="toggleMask('show',newsitem.group_id,newsitem.goods_name,newsitem.goods_images)" open-type="share"></media-list>
					</block>
					
					<block v-if="isshow2 == true" v-for="(newsitem,index2) in tab.data_limitTime" :key="index2">
						<media-list :data="newsitem"  @cancel="cancel(newsitem.order_number)" @confirm='confirm(newsitem.order_number)' @log="log(newsitem.order_number)" @evaluate="evaluate(newsitem.id)" @del="del(newsitem.id)" @pay="pay(newsitem.order_number,newsitem.pay_type)" @click="goDetail_limitTime(newsitem.id)"></media-list>
					</block>
				</scroll-view>
			</swiper-item>
		</swiper>
		
		<!-- 分享面板 -->
		<view class="mask" :class="maskState===0 ? 'none' : maskState===1 ? 'show' : ''" @click="toggleMask">
			<view class="mask-content">
				<scroll-view class="view-content" scroll-y>
					<view class="share-header">
						分享到
					</view>
					<view class="share-list">
						<button 
							v-for="(item, index) in shareList" :key="index"
							class="share-item"
							open-type="share"
						>
							<image :src="item.icon" mode=""></image>
							<text>{{item.text}}</text>
						</button>
					</view>
				</scroll-view>
			</view>
		</view>
		<uni-load-more :loadingType="loadingType" :contentText="contentText"></uni-load-more>
		<!-- <share ref="share" :contentHeight="580" :shareList="shareList" :goods_id="goods_id" ></share> -->
	</view>
</template>
<script>
	
	import mediaList from '@/components/tab-nvue/mediaList.vue';
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		onShareAppMessage(res) {
			if (res.from === 'button') {// 来自页面内分享按钮
			}
			return {
				imageUrl: this.group_img,
				title: this.group_name,
				path: '/pages/product/product?group_id=' + this.group_id  + '&sure=1'
			}
		},
		components: {
			mediaList,
			uniLoadMore
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.loadingType = 0;//将loadingType归0重置
			let o = this
			setTimeout(function () {
				o.setAjax();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		// 上拉加载
		// onReachBottom(){
		// 	if (this.timer != null) {
		// 		clearTimeout(this.timer)
		// 	}
		// 	this.timer = setTimeout(()=> {
		// 		this.loadMore()
		// 	}, 1000);
		// },
		data() {
			return {
				shareList: [
					{
						type: 1,
						icon: '/static/temp/share_wechat.png',
						text: '微信好友'
					},
					// {
					// 	type: 2,
					// 	icon: '/static/temp/share_moment.png',
					// 	text: '朋友圈'
					// },
				],
				maskState: 0, //分享面板显示状态
				goods_id:'',
				group_name:'',
				group_img: '',
				isshow: true,
				isshow1: false,
				isshow2: false,
				user_id:'',
				res:[],
				systemInfo:[],
				tabIndex: 0,
				scrollLeft: 0,
				isClickChange: false,
				newsitems: [
					{
						"loadingType":0,
						"data":[], // 普通订单
						"data_group":[], // 拼团订单
						"data_limitTime":[], // 限时订单
					},{
						"loadingType":0,
						"data":[],
						"data_group":[], // 拼团订单
						"data_limitTime":[],
					},{
						"loadingType":0,
						"data":[],
						"data_group":[], // 拼团订单
						"data_limitTime":[],
					},{
						"loadingType":0,
						"data":[],
						"data_group":[], // 拼团订单
						"data_limitTime":[],
					},{
						"loadingType":0,
						"data":[],
						"data_group":[], // 拼团订单
						"data_limitTime":[],
					},{
						"loadingType":0,
						"data":[],
						"data_group":[], // 拼团订单
						"data_limitTime":[],
					}
				],
				tabBars: [
					{
						name: '全部',
						id: 'guanzhu'
					}, {
						name: '待付款',
						id: 'tuijian'
					}, {
						name: '待发货',
						id: 'tiyu'
					}, {
						name: '已发货',
						id: 'redian'
					}, {
						name: '已完成',
						id: 'caijing'
					},{
						name: '已取消',
						id: 'nihao'
					},
				],
				ordercolor:'#0055ff',
				ordercolor1:'#000000',
				ordercolor2:'#000000',
				userinfo: '', // 支付时个人信息
				loadingText: '加载中...',
				loadingType: 0,
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				page: 1,
				page1: 1,
				page2: 1,
				timer:{},
			}
		},
		onLoad: function(e) {
			// 下不同的订单跳转到不同的订单页面
			if(e.order_number) {
				let ordernumber = e.order_number
				if (ordernumber == 'mao') {
					this.changeisshow1()
				}
				if (ordernumber == 'mpo') {
					this.changeisshow2()
				}
			}
			
			this.tabIndex = -1
			setTimeout(() => {
				this.tabIndex = e.index
			}, 1000);
			uni.getSystemInfo({
				success: (res) => {
					this.systemInfo = res.windowHeight -50
				}
			})
			uni.getStorage({
				key: 'user_id',
				success: (res) => {
				 this.user_id = res.data
				 this.setAjax()
				},
				fail() {
					uni.navigateTo({
						url:'../login/login'
					})
				}
			});
			
		},
		// onNavigationBarButtonTap:function(e){
		// 	uni.navigateTo({
		// 		url: 'recycle/recycle'
		// 	});
		//   },
		methods: {
			toggleMask(type,id,name,img){
				if (id) {
					img = JSON.parse(img)
					this.group_id = id
					this.group_name = name
					this.group_img = 'https://cx.mingmeijt.com' + img[0]
				}
				let timer = type === 'show' ? 10 : 300;
				let	state = type === 'show' ? 1 : 0;
				this.maskState = 2;
				setTimeout(()=>{
					this.maskState = state;
				}, timer)
			},
			setAjax(){
				var o = this
				// 普通订单
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/Order/index?p=1',
					method: 'POST',
					data: {
						'user_id': this.user_id,
						'session_id': uni.getStorageSync("sessionid")
					},
					header: {'Content-Type': 'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if(res.data.code == 998){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}
						let fil = res.data.data.order_list.list
						for(var i = 0; i < fil.length; i++) {
							if (fil[i].goodsInfo) {
								for(var j = 0; j < fil[i].goodsInfo.length; j++) {
									fil[i].goodsInfo[j].goods_thumb_image = 'https://cx.mingmeijt.com' + fil[i].goodsInfo[j].goods_thumb_image
								}
							}
						}
						let fil1 = fil.filter(function(item,index,array){
								return (item.status == "1" || item.status == 1);
						})
						let fil2 = fil.filter(function(item,index,array){
								return (item.status == "2" || item.status == 2);
						})
						let fil3 = fil.filter(function(item,index,array){
								return (item.status == "3" || item.status == 3);
						})
						let fil4 = fil.filter(function(item,index,array){
								return (item.status == "4" || item.status == 4);
						})
						let fil5 = fil.filter(function(item,index,array){
								return (item.status == "5" || item.status == 5);
						})
						this.newsitems[0].data = fil
						this.newsitems[1].data = fil1
						this.newsitems[2].data = fil2
						this.newsitems[3].data = fil3
						this.newsitems[4].data = fil4
						this.newsitems[5].data = fil5
					},
					fail: () => {},
					complete: () => {
					}
				});
				// 拼团订单
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/AssembleOrder/index?p=1',
					method: 'POST',
					data:{
						user_id: this.user_id,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{ 'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						let data_group = res.data.data.order_list.list
						for(var i = 0; i < data_group.length; i++) {
							data_group[i].goods_thumb = 'https://cx.mingmeijt.com' + data_group[i].goods_thumb
						}
						let data_group1 = data_group.filter(function(item,index,array){
								return (item.status == "1" || item.status == 1);
						})
						let data_group2 = data_group.filter(function(item,index,array){
								return (item.status == "2" || item.status == 2);
						})
						let data_group3 = data_group.filter(function(item,index,array){
								return (item.status == "3" || item.status == 3);
						})
						let data_group4 = data_group.filter(function(item,index,array){
								return (item.status == "4" || item.status == 4);
						})
						let data_group5 = data_group.filter(function(item,index,array){
								return (item.status == "5" || item.status == 5);
						})
						this.newsitems[0].data_group = data_group
						this.newsitems[1].data_group = data_group1
						this.newsitems[2].data_group = data_group2
						this.newsitems[3].data_group = data_group3
						this.newsitems[4].data_group = data_group4
						this.newsitems[5].data_group = data_group5
					},
					fail: () => {},
					complete: () => {}
				});
				// 限时活动
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/PanicBuyingOrder/index',
					method: 'POST',
					data:{
						'user_id': this.user_id,
						'session_id': uni.getStorageSync("sessionid")
					},
					header:{ 'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						let data_limitTime = res.data.data.order_list.list
						
						for(var i = 0; i < data_limitTime.length; i++) {
							data_limitTime[i].goods_thumb_image = 'https://cx.mingmeijt.com' + data_limitTime[i].goods_thumb_image
							data_limitTime[i].goods_thumb = 'https://cx.mingmeijt.com' + data_limitTime[i].goods_thumb
						}
						
						let data_limitTime1 = data_limitTime.filter(function(item,index,array){
								return (item.status == "1" || item.status == 1);
						})
						let data_limitTime2 = data_limitTime.filter(function(item,index,array){
								return (item.status == "2" || item.status ==2);
						})
						let data_limitTime3 = data_limitTime.filter(function(item,index,array){
								return (item.status == "3" || item.status == 3);
						})
						let data_limitTime4 = data_limitTime.filter(function(item,index,array){
								return (item.status == "4" || item.status == 4);
						})
						let data_limitTime5 = data_limitTime.filter(function(item,index,array){
								return (item.status == "5" || item.status == 5);
						})
						this.newsitems[0].data_limitTime = data_limitTime
						this.newsitems[1].data_limitTime = data_limitTime1
						this.newsitems[2].data_limitTime = data_limitTime2
						this.newsitems[3].data_limitTime = data_limitTime3
						this.newsitems[4].data_limitTime = data_limitTime4
						this.newsitems[5].data_limitTime = data_limitTime5
					},
					fail: () => {},
					complete: () => {}
				});
			},
			
			// 页面触底 加载更多
			loadMore(e) {
				let o = this
				if (this.loadingType !== 0) {//loadingType!=0;直接返回
					return false;
				}
				this.loadingType = 1;
				uni.showNavigationBarLoading();//显示加载动画
				// 普通订单列表 更多
				if(this.isshow == true) {
					this.page++;//每触底一次 page +1
					uni.request({
						url:'https://cx.mingmeijt.com/Api/Order/index?p=' + this.page,
						method: 'POST',
						data: {
							user_id: this.user_id,
							session_id: uni.getStorageSync("sessionid")
						},
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: function(res) {
							if (res.data.data.order_list.list == '' || res.data.data.order_list.list == null) {//没有数据
								o.loadingType = 2;
								uni.hideNavigationBarLoading();//关闭加载动画
								return;
							}
							let fil = res.data.data.order_list.list
							for(var i = 0; i < fil.length; i++) {
								if (fil[i].goodsInfo) {
									for(var j = 0; j < fil[i].goodsInfo.length; j++) {
										fil[i].goodsInfo[j].goods_thumb_image = 'https://cx.mingmeijt.com' + fil[i].goodsInfo[j].goods_thumb_image
									}
								}
							}
							let fil1 = fil.filter(function(item,index,array){
									return (item.status == "1" || item.status == 1);
							})
							let fil2 = fil.filter(function(item,index,array){
									return (item.status == "2" || item.status == 2);
							})
							let fil3 = fil.filter(function(item,index,array){
									return (item.status == "3" || item.status == 3);
							})
							let fil4 = fil.filter(function(item,index,array){
									return (item.status == "4" || item.status == 4);
							})
							let fil5 = fil.filter(function(item,index,array){
									return (item.status == "5" || item.status == 5);
							})
							o.newsitems[0].data = o.newsitems[0].data.concat(fil);
							o.newsitems[1].data = o.newsitems[1].data.concat(fil1);
							o.newsitems[2].data = o.newsitems[2].data.concat(fil2);
							o.newsitems[3].data = o.newsitems[3].data.concat(fil3);
							o.newsitems[4].data = o.newsitems[4].data.concat(fil4);
							o.newsitems[5].data = o.newsitems[5].data.concat(fil5);
							o.loadingType = 0;//将loadingType归0重置
							uni.hideNavigationBarLoading();//关闭加载动画
						}
					});
				}
				// 拼团 更多
				if(this.isshow1 == true) {
					this.page1++;//每触底一次 page +1
					uni.request({
						url:'https://cx.mingmeijt.com/Api/AssembleOrder/index?p=' + this.page1,
						method: 'POST',
						data: {
							user_id: this.user_id,
							session_id: uni.getStorageSync("sessionid")
						},
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: function(res) {
							if (res.data.data.order_list.list == '' || res.data.data.order_list.list == null) {//没有数据
								o.loadingType = 2;
								uni.hideNavigationBarLoading();//关闭加载动画
								return;
							}
							let data_group = res.data.data.order_list.list
							for(var i = 0; i < data_group.length; i++) {
								data_group[i].goods_thumb = 'https://cx.mingmeijt.com' + data_group[i].goods_thumb
							}
							let data_group1 = data_group.filter(function(item,index,array){
									return (item.status == "1" || item.status == 1);
							})
							let data_group2 = data_group.filter(function(item,index,array){
									return (item.status == "2" || item.status == 2);
							})
							let data_group3 = data_group.filter(function(item,index,array){
									return (item.status == "3" || item.status == 3);
							})
							let data_group4 = data_group.filter(function(item,index,array){
									return (item.status == "4" || item.status == 4);
							})
							let data_group5 = data_group.filter(function(item,index,array){
									return (item.status == "5" || item.status == 5);
							})
							o.newsitems[0].data_group = o.newsitems[0].data_group.concat(data_group);
							o.newsitems[1].data_group = o.newsitems[1].data_group.concat(data_group1);
							o.newsitems[2].data_group = o.newsitems[2].data_group.concat(data_group2);
							o.newsitems[3].data_group = o.newsitems[3].data_group.concat(data_group3);
							o.newsitems[4].data_group = o.newsitems[4].data_group.concat(data_group4);
							o.newsitems[5].data_group = o.newsitems[5].data_group.concat(data_group5);
							o.loadingType = 0;//将loadingType归0重置
							uni.hideNavigationBarLoading();//关闭加载动画
						}
					});
				}
				// 限时 更多
				if(this.isshow2 == true) {
					this.page2++;//每触底一次 page +1
					uni.request({
						url:'https://cx.mingmeijt.com/Api/AssembleOrder/index?p=' + this.page2,
						method: 'POST',
						data: {
							user_id: this.user_id,
							session_id: uni.getStorageSync("sessionid")
						},
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: function(res) {
							if (res.data.data.order_list.list == '' || res.data.data.order_list.list == null) {//没有数据
								o.loadingType = 2;
								uni.hideNavigationBarLoading();//关闭加载动画
								return;
							}
							let data_limitTime = res.data.data.order_list.list
							for(var i = 0; i < data_limitTime.length; i++) {
								data_limitTime[i].goods_thumb_image = 'https://cx.mingmeijt.com' + data_limitTime[i].goods_thumb_image
								data_limitTime[i].goods_thumb = 'https://cx.mingmeijt.com' + data_limitTime[i].goods_thumb
							}
							let data_limitTime1 = data_limitTime.filter(function(item,index,array){
									return (item.status == "1" || item.status == 1);
							})
							let data_limitTime2 = data_limitTime.filter(function(item,index,array){
									return (item.status == "2" || item.status == 2);
							})
							let data_limitTime3 = data_limitTime.filter(function(item,index,array){
									return (item.status == "3" || item.status == 3);
							})
							let data_limitTime4 = data_limitTime.filter(function(item,index,array){
									return (item.status == "4" || item.status == 4);
							})
							let data_limitTime5 = data_limitTime.filter(function(item,index,array){
									return (item.status == "5" || item.status == 5);
							})
							o.newsitems[0].data_limitTime = o.newsitems[0].data_limitTime.concat(data_limitTime);
							o.newsitems[1].data_limitTime = o.newsitems[1].data_limitTime.concat(data_limitTime1);
							o.newsitems[2].data_limitTime = o.newsitems[2].data_limitTime.concat(data_limitTime2);
							o.newsitems[3].data_limitTime = o.newsitems[3].data_limitTime.concat(data_limitTime3);
							o.newsitems[4].data_limitTime = o.newsitems[4].data_limitTime.concat(data_limitTime4);
							o.newsitems[5].data_limitTime = o.newsitems[5].data_limitTime.concat(data_limitTime5);
							o.loadingType = 0;//将loadingType归0重置
							uni.hideNavigationBarLoading();//关闭加载动画
						}
					});
				}
			},
			changeisshow:function(){
				// if(this.isshow == true) {
				// 	this.isshow = false
				// 	return
				// }
				this.isshow = true
				this.isshow1 = false
				this.isshow2 = false
				// 改字体颜色
				this.ordercolor = '#0055ff'
				this.ordercolor1 = '#000000'
				this.ordercolor2 = '#000000'
			},
			changeisshow1:function(){
				// if(this.isshow1 == true) {
				// 	this.isshow1 = false
				// 	return
				// }
				this.isshow1 = true
				this.isshow = false
				this.isshow2 = false
				// 改字体颜色
				this.ordercolor1 = '#0055ff'
				this.ordercolor = '#000000'
				this.ordercolor2 = '#000000'
			},
			changeisshow2:function(){
				// if(this.isshow2 == true) {  // 折叠功能
				// 	this.isshow2 = false
				// 	return
				// }
				this.isshow2 = true // 显示隐藏
				this.isshow = false
				this.isshow1 = false
				this.ordercolor2 = '#0055ff' // 改字体颜色
				this.ordercolor1 = '#000000'
				this.ordercolor = '#000000'
			},
			// 操作功能
			cancel(order_number) {
				// 取消订单
				uni.showModal({
					content: '确认要取消该订单吗？',
					success: (res) => {
						if (res.confirm) {
							uni.request({
								url: 'https://cx.mingmeijt.com/Api/Pay/orderCancel',
								method: 'POST',
								data: {
									user_id: this.user_id,
									order_number: order_number,
									session_id: uni.getStorageSync("sessionid")
								},
								header: {'Content-Type': 'application/x-www-form-urlencoded'},
								success: res => {
									uni.showToast({
										title:res.data.msg,
										icon:"none"
									})
									this.setAjax()
									setTimeout(() => {
										this.tabIndex = 5
									}, 1000);
								},
								fail: () => {},
								complete: () => {}
							});
						}
					}
				})
			},
			del(id) {
				// 删除订单
				uni.showModal({
					content: '确认要删除该订单吗？',
					success: (res) => {
						if (res.confirm) {
							uni.request({
								url: 'http://suhua.suzhanxue.com/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=order.op.delete&app=1&orderid='+id+'&userdeleted=1',
								method: 'POST',
								data: {
									'openid':this.openid,
								},
								header: {'Content-Type': 'application/x-www-form-urlencoded'},
								success: res => {
									
									this.setAjax()
									this.tabIndex = -1
									setTimeout(() => {
										
										this.tabIndex = 0
									}, 1000);
								},
								fail: () => {},
								complete: () => {}
							});
						}
					}
				})
			},
			confirm(order_number){
				// 确认收货
				uni.showModal({
					content: '确认已收到货了吗？',
					success: (res) => {
						if (res.confirm) {
							uni.request({
								url: 'https://cx.mingmeijt.com/Api/Pay/orderConfirm',
								method: 'POST',
								data: {
									order_number: order_number,
									user_id: this.user_id,
									session_id: uni.getStorageSync("sessionid")
								},
								header: {'Content-Type': 'application/x-www-form-urlencoded'},
								success: res => {
									this.setAjax()
									setTimeout(() => {
										this.tabIndex = 4
									}, 1000);
								},
								fail: () => {},
								complete: () => {}
							});
						}
					}
				})
			},
			// 跳转操作
			goDetail(id) {
				uni.navigateTo({
					url: 'detail/detail?id=' + id
				})
			},
			goDetail_group (id) {
				uni.navigateTo({
					url: 'detail/detail?group_id=' + id
				})
			},
			goDetail_limitTime (id) {
				uni.navigateTo({
					url: 'detail/detail?limitTime_id=' + id
				})
			},
			evaluate(id){
				uni.navigateTo({
					url: 'comment/comment?id=' + id
				});
			},
			log(order_number){
				uni.navigateTo({
					url: 'express/express?order_number='+ order_number
				});
			},
			share(order_number){
				// this.$refs.share.toggleMask();
			},
			pay(order_number,pay_type){
				let o = this
				if ( pay_type == 1 || pay_type == 4 || pay_type == 5) { // 佣金支付
					uni.request({
						url: 'https://cx.mingmeijt.com/Api/Pay/payOrder',
						method: 'POST',
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						data:{
							user_id: this.user_id,
							order_number: order_number,
							session_id: uni.getStorageSync("sessionid")
						},
						success: res => {
							if(res.data.code == 999){
								uni.navigateTo({
									url:'/pages/999/999'
								})
							};
							uni.showToast({
								title: res.data.msg,
								icon:'none'
							})
							o.setAjax()
							if(res.data.code == 200) {
								setTimeout(() => {
									this.tabIndex = 2
								}, 1000);
							}
						},
						fail: () => {},
						complete: () => {}
					});
					return
				}
				console.log(pay_type)
				
				if ( pay_type == 3 ) { // 微信支付
					uni.request({
						url: 'https://cx.mingmeijt.com/Api/Pay/wechatH5payApi',
						method: 'POST',
						data: {
							order_number: order_number,
							session_id: uni.getStorageSync("sessionid")
						},
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: (res) => {
							if(res.data.code == 999){
								uni.navigateTo({
									url:'/pages/999/999'
								})
							};
							var userinfo = res.data.data
							console.log(userinfo)
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: userinfo.timeStamp,
								nonceStr: userinfo.nonceStr,
								package: userinfo.package,
								signType: userinfo.signType,
								paySign: userinfo.paySign,
								order_number: userinfo.order_number,
								appId: userinfo.appId,
								success: function(res) {
									// 微信支付成功之后,吊起的接口刷新页面
									uni.request({
										url: 'https://cx.mingmeijt.com/Api/Pay/payOrder',
										method: 'POST',
										header:{'Content-Type':'application/x-www-form-urlencoded'},
										data:{
											user_id: o.user_id,
											order_number: order_number,
											session_id: uni.getStorageSync("sessionid")
										},
										success: res => {
											uni.showToast({
												title: res.data.msg,
												icon:'none'
											})
											o.setAjax()
											if(res.data.code == 200) {
												setTimeout(() => {
													o.tabIndex = 2
												}, 1000);
											}
										},
										fail: () => {},
										complete: () => {}
									});
									
								},
								fail: function(err) {
									console.log(err)
									console.log('支付失败----------------------')
									return
								}
							});
							
							
						}
					});
					return
				}
			},
			// tab切换功能
			async changeTab(e) {
				let index = e.target.current;
				if (this.isClickChange) {
					this.tabIndex = index;
					this.isClickChange = false;
					return;
				}
				let tabBar = await this.getElSize("tab-bar"),
					tabBarScrollLeft = tabBar.scrollLeft;
				let width = 0;

				for (let i = 0; i < index; i++) {
					let result = await this.getElSize(this.tabBars[i].id);
					width += result.width;
				}
				let winWidth = uni.getSystemInfoSync().windowWidth,
					nowElement = await this.getElSize(this.tabBars[index].id),
					nowWidth = nowElement.width;
				if (width + nowWidth - tabBarScrollLeft > winWidth) {
					this.scrollLeft = width + nowWidth - winWidth;
				}
				if (width < tabBarScrollLeft) {
					this.scrollLeft = width;
				}
				this.isClickChange = false;
				this.tabIndex = index; //一旦访问data就会出问题
			},
			getElSize(id) { //得到元素的size
				return new Promise((res, rej) => {
					uni.createSelectorQuery().select("#" + id).fields({
						size: true,
						scrollOffset: true
					}, (data) => {
						res(data);
					}).exec();
				})
			},
			async tapTab(e) { //点击tab-bar
				if (this.tabIndex == e.target.dataset.current) {
					return false;
				} else {
					this.isClickChange = true;
					this.tabIndex = e.target.dataset.current
				}
			}
		}
	}
</script>

<style lang="scss">
	uni-page-body{height:100%;}
	/* 分享面板 */
	.mask{
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0,0,0,0);
		z-index: 9995;
		transition: .3s;
		
		.mask-content{
			width: 100%;
			min-height: 30vh;
			max-height: 70vh;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: .3s;
			overflow-y:scroll;
		}
		&.none{
			display: none;
		}
		&.show{
			background: rgba(0,0,0,.4);
			
			.mask-content{
				transform: translateY(0);
			}
		}
	}
	.share-header{
		height: 110upx;
		font-size: $font-base+2upx;
		color: font-color-dark;
		display:flex;
		align-items:center;
		justify-content: center;
		padding-top: 10upx;
		&:before, &:after{
			content: '';
			width: 240upx;
			heighg: 0;
			border-top: 1px solid $border-color-base;
			transform: scaleY(.5);
			margin-right: 30upx;
		}
		 &:after{
			 margin-left: 30upx;
			 margin-right: 0;
		 }
	}
	.share-list{
		display:flex;
		flex-wrap: wrap;
	}
	.share-item{
		margin: 0;padding: 0;border: 1px solid transparent;outline: none;background: transparent;border: none;border: 0;
		min-width: 33.33%;
		display:flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 180upx;
		image{
			width: 80upx;
			height: 80upx;
			margin-bottom: 16upx;
		}
		text{
			font-size: $font-base;
			color: $font-color-base;
		}
	}
	.share-item::after{
		border: none;
	}
</style>